package com.situ.day15;

import java.beans.MethodDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

public class Demo {
	@Test
	public void test1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor();
		Student student = (Student) constructor.newInstance();
		Method method = clazz.getMethod("setName", String.class);
		method.invoke(student, "李四");
		System.out.println(student);
	}
	@Test
	public void test2() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz1 = Student.class;
		Constructor constructor = clazz1.getConstructor(String.class);
		Student student = (Student) constructor.newInstance("李四");
		System.out.println(student);
	}
	@Test
	public void test3() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor();
		Student student = (Student)constructor.newInstance();
		Method method = clazz.getMethod("setName", String.class);
		method.invoke(student, "王五");
		System.out.println(student);
	}
	@Test
	public void test4() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor(String.class);
		Student student = (Student) constructor.newInstance("张三");
		System.out.println(student);
	}
	@Test
	public void test5() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor();
		Student student = (Student)constructor.newInstance();
		Method method = clazz.getMethod("setName", String.class);
		method.invoke(student, "张三");
		System.out.println(student);
	}
	@Test
	public void test6() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor(String.class);
		Student student = (Student)constructor.newInstance("张三");
		System.out.println(student);
	}
	@Test
	public void test7() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor();
		Student student = (Student)constructor.newInstance();
		Method method = clazz.getMethod("setName", String.class);
		method.invoke(student, "张三");
		System.out.println(student);
	}
	@Test
	public void test8() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor(String.class);
		Student student = (Student)constructor.newInstance("张三");
		System.out.println(student);
	}
	@Test
	public void test9() throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor();
		Student student = (Student)constructor.newInstance();
		Method method = clazz.getMethod("setName", String.class);
		method.invoke(student, "张三");
		System.out.println(student);
	}
	@Test
	public void test10() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clazz = Student.class;
		Constructor constructor = clazz.getConstructor(String.class);
		Student student = (Student)constructor.newInstance("李四");
		System.out.println(student);
	}

}
